package com.library.job;

import javax.mail.internet.InternetAddress;

import com.liferay.mail.service.MailServiceUtil;
import com.liferay.portal.kernel.mail.MailMessage;
import com.liferay.portal.kernel.messaging.BaseMessageListener;
import com.liferay.portal.kernel.messaging.Message;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;

public class UserNotify extends BaseMessageListener {

	@Override
	protected void doReceive(Message message) throws Exception {
		// TODO Auto-generated method stub

		System.out.println("the notification job is getting invoked....");
		
		MailMessage mailMessage = new MailMessage();
		
		InternetAddress from = new InternetAddress();
		from.setAddress(PropsUtil.get(PropsKeys.ADMIN_EMAIL_FROM_ADDRESS));
		from.setPersonal(PropsUtil.get(PropsKeys.ADMIN_EMAIL_FROM_NAME));
		mailMessage.setFrom(from);
		
		InternetAddress to = new InternetAddress();
		to.setAddress("admin@library.com");
		to.setPersonal("Library Admin");
		mailMessage.setTo(to);
		
		mailMessage.setSubject("today is the due date for returning....");
		
		String body = "this is the body of the email. Dear <user-name>";
		
		mailMessage.setBody(body);
		MailServiceUtil.sendEmail(mailMessage);
	}
}